package com.kgc.scd.service.impl;

import com.kgc.scd.entity.ShopOrder;
import com.kgc.scd.mapper.ShopOrderMapper;
import com.kgc.scd.service.ShopOrderServerService;
import com.kgc.scd.vo.ShopOrderVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created On : 2022/11/17.
 * <p>
 * Author : Administrator
 * <p>
 * Description: ShopOrderServerServiceImpl
 */
@Slf4j
@Service
public class ShopOrderServerServiceImpl implements ShopOrderServerService {



    @Autowired(required = false)
    private ShopOrderMapper shopOrderMapper;
    @Override
    public ShopOrderVO getShopOrderById(String orderId) {
        ShopOrder shopOrder=shopOrderMapper.selectById(orderId);
        ShopOrderVO shopOrderVO=new ShopOrderVO();
        BeanUtils.copyProperties(shopOrder,shopOrderVO);
        if (shopOrder.getShoppingStatus()==1){
            shopOrderVO.setShoppingStatus("未支付");
        }
        if (shopOrder.getShoppingStatus()==3){
            shopOrderVO.setShoppingStatus("支付成功/未发货");
        }
        return shopOrderVO;
    }

    @Override
    public void updateSHopOrderStatus(ShopOrderVO shopOrderVO) {

        ShopOrder shopOrder=new ShopOrder();
        BeanUtils.copyProperties(shopOrderVO,shopOrder);
        if (shopOrderVO.getShoppingStatus().equals("支付成功/未发货")){
            shopOrder.setShoppingStatus(3);
        }
        if (shopOrderVO.getShoppingStatus().equals("未支付")){
            shopOrder.setShoppingStatus(1);
        }

        shopOrderMapper.updateById(shopOrder);
    }

    @Override
    public void delOrderById(String orderId) {


        shopOrderMapper.deleteById(orderId);
    }
}
